#pragma once

class CSpreadsheet;

class CDisturbance 
{
public:
    CDisturbance(){;}
    ~CDisturbance(){;}

    // load data from spreadsheet to here
    virtual void load(const vector<CSpreadsheet*>& vSpreadsheet_,const string& strFileName_ );
    virtual void precompute();
    virtual void precomputeEachTrial();
    virtual void clear();

private:
    //Helpers
    double sumOfSines(const int& nSines_, const int& nDiffOrder_, const CMatrix<double>& mAa_, const CMatrix<double>& mKay_, const double& dRunTime_, const CMatrix<double>& mRho_);

    void precomputeDisturbance(const int& nSines_, const int& nDiffOrder_, const CMatrix<double>& mAa_, const CMatrix<double>& mKay_, const vector<double>& vRunTime_, const CMatrix<double>& mRho_, CMatrix<double>* pmDisturbanceValues_);
    void precomputeRho( CMatrix<double>* pmRho_);
    void precomputeTime(vector<double>* pRunTime_);
public:
    //retrievers
    const CMatrix<double>& rho() const {return _mRho;}
          CMatrix<double>& setRho()    {return _mRho;}
    const double& deltaTee() const {return _dDeltaTee;}
          double& setDeltaTee()    {return _dDeltaTee;}
    const CMatrix<double>& disturbanceValues()    const   {return _mDisturbanceValues;}
          CMatrix<double>& setDisturbanceValues()            {return _mDisturbanceValues;}  
    // Disturbance spectra file
    const CMatrix<double>& kay() const {return _mKay;}
          CMatrix<double>& setKay()    {return _mKay;}
    const CMatrix<double>& aa() const {return _mAa;}
          CMatrix<double>& setAa()    {return _mAa;}
    const int& diffOrder() const {return _nDiffOrder;}
          int& setDiffOrder()    {return _nDiffOrder;}
    const int& numSines() const {return _nSines;}
          int& setNumSines()    {return _nSines;}
    const int& trialLengthinSecs() const {return _nRunTimeinSecs;}
          int& setTrialLengthinSecs()    {return _nRunTimeinSecs;}
    const double& preRunTimeinSecs() const {return _dPrerunTimeinSecs;}
          double& setPreRunTimeinSecs()    {return _dPrerunTimeinSecs;}
    const double& extraSecs() const {return _dExtraTimeinSecs;}
          double& setExtraSecs()    {return _dExtraTimeinSecs;}
    const int& frameRate() const {return _nFrameRate;}
          int& SetFrameRate()    {return _nFrameRate;}
    const double& disturbanceGain() const {return _dDisturbanceGain;}
          double& setDisturbanceGain()    {return _dDisturbanceGain;}
    const vector<double>& runTime() const {return _vRunTime;}
          vector<double>& setRunTime()    {return _vRunTime;}
    const string& nameDisturbance() const {return _strNameDisturbance;}
          string& setNameDisturbance() {return _strNameDisturbance;}
    inline const int totalFrames() const {return (preRunTimeinSecs()+trialLengthinSecs()+extraSecs())*frameRate();}
    inline const int preRunFrames() const {return preRunTimeinSecs()*frameRate();}
protected:
    // spectra file
    CMatrix<double> _mKay; // selected frequency numbers
    CMatrix<double> _mAa; // amplitude
    CMatrix<double> _mRho;
    CMatrix<double> _mDisturbanceValues; 
    vector<double>  _vRunTime; //// the vector stores the absolute time in seconds for each frame. 
    string _strNameDisturbance;
    int _nRunTimeinSecs;
    int _nDiffOrder;
    int _nSines;
    int _nFrameRate;// frame rate
    double _dDeltaTee;
    double _dPrerunTimeinSecs;
    double _dDisturbanceGain;
    double _dExtraTimeinSecs;
};